<template>
	<view class="container">
		<template>
			<view class="search-header-box">
				<view class="search-header">
					<view class="search-searchbox">
						<view class="iconfont iconsousuohome stockIconfont" @tap="search()"></view>
						<input class="search-input" confirm-type="search" v-model="searchText" placeholder="请输入商品信息"
						@confirm="search()"></input>
						<!-- <view class="search-clear iconfont iconguanbi1" v-if="searchKey"
						@tap="searchKeyFun"></view> -->
					</view>
					<view class="dateClass" @tap="showFun()">
						<image class="dateImg" src="../../../static/img/date.png" mode=""></image>
					</view>
				</view>
			</view>
		</template>
		<view class="stockNumber">
			<view class="warehousing" @tap="goWarehousingList">
				<view class="warehousNum">
					+{{inCount}}
				</view>
				<view class="warehousWord">
					入库(个)
				</view>
			</view>
			<view class="warehousing" @tap="goDeliveryStock">
				<view class="warehousNum">
					-{{outCount}}
				</view>
				<view class="warehousWord">
					出库(个)
				</view>
			</view>
			<view class="warehousing" @tap="goStockPresent">
				<view class="warehousNum">
					{{nowStockCount}}
				</view>
				<view class="warehousWord">
					库存现状(个)
				</view>
			</view>
		</view>
		<view class="stickSecurity" v-if="safeStockList.length>0">
			<view class="securitytitle" @tap="moreFun">
				<view class="securityWord">
					库存安全预警
				</view>
				<view class="securityIcon" >
					<i class='iconfont iconxiangyou'></i>
				</view>
			</view>
			<view class="securityInfo">
				<view class="stockLess" v-for="(item,index) in safeStockList" :key='index' @tap="goDetail(item)">
					<view class="stockLeft">
						{{item.goodsName}}<span style='margin-left: 20rpx;'>{{item.goodsMatcode}}</span>
					</view>
					<view class="stockRight">
						剩余<span class='fStockNum'>{{item.stockNum}}</span>个
					</view>
				</view>
			</view>
		</view>
		<date-popup @determine='determine' :beginDate='beginDate' :endDate='endDate' :popupShow='popupShow' @colosePopup='colosePopup'></date-popup>
		<loading></loading>
		<tui-modal></tui-modal>
	</view>
</template>

<script>
	import datePopup from "@/components/datePopup/index.vue"
	export default {
		components: {
			datePopup,
		},
		data() {
			return {
				popupShow:false,
				searchText:'',
				beginDate:'',
				endDate:'',
				
				inCount:0, //入库数量
				outCount:0, //出库数量
				nowStockCount:0, //库存现状数量
				// safeStockList:[{
				// 	fGoodsId:'1234545642',
				// 	fGoodsName:'就的官方电话上课',
				// 	fGoodsMatcode:'1123212',
				// 	fStockNum:2,
				// 	fSafeStockNum:0,
				// },{
				// 	fGoodsId:'12341564',
				// 	fGoodsName:'第三方第三方第三方第三方第三方第三方第三方第三方第三方第三方',
				// 	fGoodsMatcode:'12312',
				// 	fStockNum:1,
				// 	fSafeStockNum:1,
				// },{
				// 	fGoodsId:'245646',
				// 	fGoodsName:'反对和电话',
				// 	fGoodsMatcode:'1231321341',
				// 	fStockNum:0,
				// 	fSafeStockNum:0,
				// },{
				// 	fGoodsId:'45426556',
				// 	fGoodsName:'变得更好的话',
				// 	fGoodsMatcode:'213456465',
				// 	fStockNum:2,
				// 	fSafeStockNum:1,
				// }],
				safeStockList:[]
			}
			
		},
		onLoad() {
			// #ifdef H5
			   this.$wechat.noShare();
			// #endif
			this.safeStockFun()
			this.homeCountFun()
		},
		onShow() {
			// this.safeStockFun()
			// this.homeCountFun()
		},
		mounted() {
			// 监听页面刷新
			this.$eventHub.$off('addStockNum');
			this.$eventHub.$on('addStockNum', () => {
			  this.homeCountFun();
			});
			// 监听页面刷新
			this.$eventHub.$off('reduceStockNum');
			this.$eventHub.$on('reduceStockNum', () => {
			  this.homeCountFun();
			});
			// 监听页面刷新
			this.$eventHub.$off('setStock');
			this.$eventHub.$on('setStock', () => {
			  this.homeCountFun();
			});
		},
		methods: {
			search(){
				this.safeStockFun()
				this.homeCountFun()
			},
			// 获取数量
			homeCountFun(){
				var param={
					searchText:this.searchText,
					beginDate:this.beginDate,
					endDate:this.endDate
				}
				this.$http.homeCount(param).then((res) => {
					if(res.status === 0) {
						console.log(res.data)
						this.inCount=res.data.inCount
						this.outCount=res.data.outCount
						this.nowStockCount=res.data.nowStockCount
					}
				})
			},
			// 库存安全预警
			safeStockFun(){
				let param={
					current:1,
					pageSize:10,
					searchText:this.searchText,
				}
				this.$http.safeStock(param).then((res) => {
					if(res.status === 0) {
						console.log(res.data)
						this.safeStockList=res.data.records
					}
				})
			},
			determine(data,flag){
				if(flag=='clear'){
					this.beginDate=''
					this.endDate=''
				}else{
					this.beginDate=data[0]
					this.endDate=data[1]
				}
				this.popupShow=false
				console.log(data)
				console.log(this.beginDate)
				console.log(this.endDate)
				this.homeCountFun()
			},
			showFun(){
				this.popupShow=true
				console.log(this.popupShow)
			},
			colosePopup(){
				this.popupShow=false
			},
			unipopupFun(e) {
				console.log(e.show)
				this.couponShow = e.show
			},
			moreFun(){
				uni.navigateTo({
					url:'./securityMoreList?searchText='+this.searchText+'&beginDate='+this.beginDate+'&endDate='+this.endDate
				})
			},
			goStockPresent(){
				uni.navigateTo({
					url:'./stockPresent?searchText='+this.searchText+'&beginDate='+this.beginDate+'&endDate='+this.endDate
				})
			},
			goDetail(item){
				uni.navigateTo({
					url:'../goodsStockDetail/goodsStockDetail?goodsId='+item.goodsId+'&goodsMatcode='+item.goodsMatcode+'&type=present'
				})
			},
			goWarehousingList(){
				uni.navigateTo({
					url:'../warehousingList/warehousingList?searchText='+this.searchText+'&beginDate='+this.beginDate+'&endDate='+this.endDate
				})
			},
			goDeliveryStock(){
				uni.navigateTo({
					url:'../deliveryStock/deliveryStock?searchText='+this.searchText+'&beginDate='+this.beginDate+'&endDate='+this.endDate
				})
			},
			
		}
	}
</script>

<style lang="scss">
.container {
	padding-bottom: 100rpx;
	color: #333;

	.search-header-box {
		width: 100%;
		background: #fff;
		position: fixed;
		z-index: 99991;
		left: 0;
		top: 0;
		border-bottom: 2rpx solid $borderColor;
	}
	.search-header {
		display: flex;
		align-items: center;
		padding: 0 20rpx;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
	}
	.search-searchbox {
		flex: 1;
		height: 70rpx;
		border-radius: 80rpx;
		font-size: 24rpx;
		// background: $borderColor;
		border:2rpx solid $themeColor1;
		padding: 6rpx 15rpx;
		box-sizing: border-box;
		color: #999;
		display: flex;
		align-items: center;
		overflow: hidden;
		.stockIconfont{
			font-size: 38rpx;
		}
	}
	.search-input {
		text-align: left !important;
		margin-left: 12rpx;
		width: 100% !important;
		background-color: #fff !important;
		color:#121212;
		font-size: 28rpx;
		.uni-input-input {
			width: 100%;
			font-size: 30rpx;
		}
	}
	
	.search-text {
		font-size: 32rpx;
		color: #444;
		margin: 0 20rpx 0 30rpx;
		color: $red;
	}
	.search-search-text {
		padding-left: 16rpx;
	}
	.search-search-key {
		max-width: 80%;
		height: 100%;
		padding: 0 16rpx;
		margin-left: 12rpx;
		display: flex;
		align-items: center;
		border-radius: 15px;
		background: rgba(0, 0, 0, 0.5);
		color: #fff;
	}
	.dateClass{
		width: 50rpx;
		height: 50rpx;
		margin-left: 40rpx;
		
		.dateImg{
			width: 100%;
			height: 100%;
		}
	}
	.stockNumber{
		display: flex;
		    margin-top: 100rpx;
		    padding: 40rpx;
		    justify-content: space-between;
		.warehousing{
			width: 30%;
			background: #FFFFFF;
			box-shadow: 0px 4rpx 24rpx 0px rgba(0, 0, 0, 0.1);
			border-radius: 20rpx;
			height: 200rpx;
			text-align: center;
			.warehousNum{
				font-size: 56rpx;
				font-weight: 400;
				color: #EA655E;
				line-height: 90rpx;
			}
			.warehousWord{
				font-size: 28rpx;
				font-weight: 400;
				color: #111111;
				line-height: 80rpx;
			}
		}
		
	}
	.stickSecurity{
		background-color: #fff;
		padding-bottom: 40rpx;
		.securitytitle{
			padding: 20rpx;
			display: flex;
			justify-content:space-between;
			align-items: center;
			.securityWord{
				font-size: 32rpx;
				font-weight: bold;
				color: #111111;
			}
			.securityIcon{
				color: #999999;
			}
		}
		.securityInfo{
			padding: 0rpx 25rpx;
			.stockLess{
				padding: 10rpx 0;
				display: flex;
				justify-content:space-between;
				align-items: center;
				.stockLeft{
					width: 450rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					font-size: 32rpx;
					color: #111111;
				}
				.stockRight{
					font-size: 24rpx;
					color: #111111;
					.fStockNum{
						color: #EA655E;
					}
				}
			}
			
		}
	}
	.uni-tip-title {
		// text-align: center;
		// font-weight: bold;
		font-size: 16px;
		color: #333;
		display: flex;
		justify-content: space-between;
		padding: 15rpx;
	}
	
	.uni-tip-box {
		padding: 15rpx;
		width: 100%;
		background: #fff;
		box-sizing: border-box;
	
		// border-radius: 20px 20rpx 0 0;
	}
}
</style>
